﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lsk.Data;
using System.Data.Entity.Core.Objects;
using Lsk.Business.DTO;

namespace Lsk.Business
{
   
    public class News
    {
        private Lsk.Data.lskEntities _entity;

        public News()
        {
            _entity = new lskEntities();
        }

        
        public IEnumerable<GetNews_Result> GetNews()
        {
             ObjectResult<GetNews_Result> news = _entity.GetNews(0);
            

             return news.AsEnumerable<GetNews_Result>();
        }

        public NewsMessage GetNew(string guid)
        {
            NewsMessage response = new NewsMessage();
            Mobile_News data = (from a  in _entity.Mobile_News where a.NewsId == new Guid(guid) select a).FirstOrDefault();
            response.MobileNews = data;
            int pictureCount = (from a in _entity.AW_Picture where a.PropertyId == new Guid(guid) select a).Count();
            IEnumerable<GetPictureByID_Result> picture;
            if (pictureCount > 0)
            {
                picture = _entity.GetPictureByID(guid).ToList();
                response.pictureList = picture;
            }
          //  response.pictureList = _entity.GetPictureByID(guid);
            return response;


        }

    }
}
